import * as React from "react"
import { useHistory } from "react-router-dom"
import {
  message
} from "antd"
import { ICompany } from "../../types"
import * as api from '../../services/api'
import Company from "../../components/Company"

export default function Companylist() {
  const history = useHistory()
  const [data, setData] = React.useState<ICompany[]>([])
  const getData = async () => {
    const handle = message.loading('正在更新数据...', 0)
    const res = await api.companylist()
    if (res.stat === 'OK') {
      setData(res.rows)
    }
    handle()
  }
  React.useEffect(() => {
    const handle = message.loading('正在加载数据...', 0)
    const getData = async () => {
      const res = await api.companylist()
      if (res.stat === 'OK') {
        setData(res.rows)
      }
      handle()
    }
    getData()
  }, [history])
  return Company(data, getData, true)
}

